package com.xi.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xi.springboot.entity.Record;
import com.xi.springboot.entity.Url;
import com.xi.springboot.entity.UrlVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: xjs
 * @Date: 2022/11/19/10:59
 * @Description:
 */
@Mapper
public interface UrlMapper extends BaseMapper<Url> {
    String selectOriginUrlBySeparateAndShortUrl(@Param("separate") String separate,@Param("shortUrl") String shortUrl);
//    @Select("select * from tbl_url where userId = #{userId}")
//    @Results(id = "UserMap",value = {
//          @Result(column = "userId",property = "user")
//    })
//    List<Url> selectUrlById(Long userId);
    @Select("SELECT username,separate, url.id,origin_url,short_url_id,last_visit,visits FROM tbl_url url JOIN tbl_user on url.user_id = tbl_user.id")
      IPage<UrlVo> selectByPage(IPage<UrlVo> page);
    @Select("SELECT username,separate, url.id,origin_url,short_url_id,last_visit,visits FROM tbl_url url JOIN tbl_user on url.user_id = tbl_user.id WHERE visits = (SELECT max(visits) FROM tbl_url)")
     UrlVo selectPopular();
//    List<Record>getPageById(IPage<Record> page);
}
